# Copyright (c) 2019 Presto Labs Pte. Ltd.
# Author: inkyu

from collections import namedtuple

AlphaSpec = namedtuple('AlphaSpec', ['name', 'target', 'reference', 'alpha'])

Loaded = namedtuple('Loaded', ['name', 'target', 'reference', 'alpha_funcs'])
LoadedAlphaGroup = namedtuple('LoadedAlphaGroup', ['name', 'products', 'alpha_dict'])
RidgeModel = namedtuple('RidgeModel', ['name', 'symbol', 'alpha_groups'])


class Profile(namedtuple('Profile', ['name', 'target', 'reference', 'alphas'])):
  def load(self):
    alpha_funcs = []
    for alpha_func in self.alphas:
      alpha_funcs.append(alpha_func)
    return Loaded(self.name, self.target, self.reference, alpha_funcs)


class AlphaGroup(namedtuple('AlphaGroup', ['name', 'products', 'alpha_funcs'])):
  def load(self):
    alpha_dict = dict()
    name_prefix = '/'.join([self.name, '^'.join(self.products)])
    for alpha_func in self.alpha_funcs:
      name = name_prefix + '/' + alpha_func.__name__
      alpha_dict[name] = alpha_func
    return LoadedAlphaGroup(self.name, self.products, alpha_dict)
